#include "glinterfacedemo.h"
#include <QBciTarget>
#include <QSinWaveGenerator>

void GlInterface::targetsInit() {
  QString iconPath = ":/icon/";
  QString soundPath = ":/sound/";
  auto getSound = [&soundPath](const QString &name) {
    return soundPath + name + ".wav";
  };
  auto getIcon = [&iconPath](const QString &name) {
    return iconPath + name + ".png";
  };

  const int w = 200, h = 200, wm = 30, hm = 50;
  const int cCnt = 9, rCnt = 4;
  auto addT = [=](const int &row, const int &col) {
    int i = row * rCnt + col;
    double f = 20 + 0.1 * i;
    QString name = QString::number(f);
    QBciTarget *target =
        new QBciTarget(name, getIcon("arrow_g"), getIcon("arrow"));
    target->setGeometry(col * (w + wm), row * (h + hm), w, h);
    target->setShowLabel(name, QBciTargetInterface::South);

//    auto wave = QSharedPointer<QSinWaveGenerator>::create();
//    wave->setFreq(f);
//    target->installWaveGenerator(wave);
    target->render->setWaveType(QBciRender::sin);
    target->render->setFreq(f);
    this->targets()->addTarget(target);
  };

  for (int r = 0; r < rCnt; ++r) {
    for (int c = 0; c < cCnt; ++c) {
      addT(r, c);
    }
  }
}
